<template>
    <div class="app-container">
        <levelbar></levelbar>
        <div class="content">
            <TableLayout form-title=""> 
                <el-form :model="formInline" class="formInline" label-width="90px" label-position="right" slot="form" v-collapse="false">          
                    <el-row :gutter="41">
                        <el-col :span="8">
                            <el-form-item label="所属省">
                                <province v-model="formInline.fProvinceId"></province>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="所属市">
                                <city v-model="formInline.fCityId" :province="formInline.fProvinceId"></city>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="所属区">
                                <region v-model="formInline.fAreaId" :city="formInline.fCityId"></region>
                            </el-form-item>
                        </el-col>
                    </el-row>                
                    <el-row :gutter="41">
                        <el-col :span="8">
                            <el-form-item label="学校名称">
                                <school v-model="formInline.schoolName" :provinceId="formInline.fProvinceId" :cityId="formInline.fCityId" :areaId="formInline.fAreaId" style="width:100%" @change='schoolChange'></school>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="复核状态">
                                <el-select v-model="formInline.firstStatus" placeholder="请选择" style="width:100%">
                                    <el-option v-for="item in formInline.sateList" :key="item.value" :label="item.value" :value="item.label"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item label="申请日期" label-width="90px">
                                <el-row>  
                                    <el-col :span="11">
                                        <el-date-picker :editable="false" :clearable="true" :state="false" v-model="formInline.startDate" type="date" format="yyyy-MM-dd" placeholder="选择开始日期" :picker-options="formInline.pickerOptions1" @change="dateChange1" style="width:100%">
                                        </el-date-picker>
                                    </el-col>
                                    <el-col :span="2" align="center">至</el-col>
                                    <el-col :span="11">
                                        <el-date-picker :editable="false" :clearable="true" :state="false" v-model="formInline.endDate" type="date" placeholder="选择结束日期" :picker-options="formInline.pickerOptions2"  @change="dateChange2" style="width:100%">
                                        </el-date-picker>
                                    </el-col> 
                                </el-row>                
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row class="top-line">
                        <el-col :span="4" :offset="20"> 
                            <el-button type="primary" class="top-btn" @click="onSubmit">查询</el-button>
                        </el-col>
                    </el-row>
                </el-form>
                <div class="table-title" slot="table-title">
                    <div class="btnPosition">
                        <el-button  @click="exportBtn">批量通过</el-button>
                    </div>
                </div>
                <el-table border ref="multipleTable" :data="dataList"  style="width: 100%" v-loading="loading" tooltip-effect="dark" @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55" :selectable="fn"></el-table-column>
                    <el-table-column align="center" label="申请时间">
                        <template scope = "scope">
                            {{scope.row.applyTime === null? '--': scope.row.applyTime.substr(0,16)}}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="初审时间">
                        <template scope = "scope">
                            {{scope.row.time === null? '--': scope.row.time.substr(0,16)}}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="学校名称">
                        <template scope = "scope">
                            {{scope.row.schoolName === null? '--': scope.row.schoolName}}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="银行卡姓名">
                        <template scope = "scope">
                            {{scope.row.accountName === null? '--': scope.row.accountName}}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="银行卡号">
                        <template scope = "scope">
                            {{scope.row.bankCard === null? '--': scope.row.bankCard}}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="所属银行">
                        <template scope = "scope">
                            {{scope.row.bankName === null? '--': scope.row.bankName}}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="所属支行">
                        <template scope = "scope">
                            {{scope.row.subBankName === null? '--': scope.row.subBankName}}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="结算金额（元）">
                        <template scope = "scope">
                            {{scope.row.money === null? '--': scope.row.money | moneySwitch}}
                        </template>
                    </el-table-column>
                    <el-table-column align="center" label="复核状态" width="90">
                        <template scope = "scope">
                            {{scope.row.status === null? '--': scope.row.status}}
                        </template>
                    </el-table-column>
                    <el-table-column align="left" label="操作" width="100">
                        <template scope = "scope">
                            <el-button v-if="Object.is(scope.row.status,'未处理')" @click="btnTrial(scope.row)" type="text" class="btn">复核</el-button>
                            <!-- <span v-else type="text" class="text-block">-</span> -->
                            <el-button @click="btnDetails(scope.row)" type="text" class="btn">详情</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="pagination-container" style="text-align:right">
                        <el-pagination
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="listQuery.total"
                            :current-page.sync="listQuery.page"
                            :page-sizes="config.pageSizes"
                            :page-size="config.pageSize"
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange">
                        </el-pagination>
                </div>
            </TableLayout>
        </div>

        <!-- 批量通过 -->
        <unifyallow @sortAllow="sortAllow" v-if="modifyAllow.dialogFormVisible" :modifyAllow="modifyAllow"></unifyallow>

        <!-- 复核 -->
        <unifytrial @sortTrial="sortTrial" v-if="modifyTrial.dialogFormVisible" :modifyTrial="modifyTrial"></unifytrial>
    </div>
</template>

<script>
import Levelbar from '../layout/Levelbar';
import TableLayout from 'components/TableLayouts';
import { mapState, mapActions } from 'vuex';
import moment from 'moment';
import province from 'components/CascadeRegion/province';
import city from 'components/CascadeRegion/city';
import region from 'components/CascadeRegion/region';
import unifyallow from './comps/unifyallow';
import unifytrial from './comps/unifytrial';
import { pageCardSettlement } from 'api/settlemain';
import school from 'components/SchoolClasss/school';
export default {
    name: 'settleManagement',
    components: {
        TableLayout,
        Levelbar,
        province,
        city,
        region,
        unifyallow,
        unifytrial,
        school
    },
    data() {
        return {
            activeName: 'integral',
            formInline: {
                fProvinceId: '',
                fAreaId: '',
                fCityId: '',
                schoolId: '',
                schoolName: '',
                sateList: [
                    {
                        label: '',
                        value: '请选择'
                    },
                    {
                        label: '10',
                        value: '未处理'
                    },
                    {
                        label: '20',
                        value: '已通过'
                    },
                    {
                        label: '30',
                        value: '已驳回'
                    }
                ],
                firstStatus: '',
                startDate: '', // 注册开始时间
                endDate: '', // 注册结束时间
                pickerOptions1: {},
                pickerOptions2: {}
            },
            loading: false,
            dataList: [],
            listQuery: {
        // 分页
                page: 1,
                total: 0
            },
            multipleSelection: [],
            modifyAllow: {
                dialogFormVisible: false
            },
            modifyTrial: {
                dialogFormVisible: false
            }
        };
    },
    computed: {
        ...mapState({
            config: state => state.config.table
        })
    },
    watch: {
    // 局部刷新列表
        cacheUpdated(val) {
            val && this.searchFetchData();
        }
    },
    created() {
        this.searchFetchData();
    },
    methods: {
        ...mapActions(['ChangePageSize']),
    // 开始日期選擇
        dateChange1(date) {
            this.formInline.pickerOptions2 = {
                disabledDate(time) {
                    return time.getTime() < new Date(date).getTime() - 864e5;
                }
            };
        },

    // 结束日期选择
        dateChange2(date) {
            this.formInline.pickerOptions1 = {
                disabledDate(time) {
                    return time.getTime() > new Date(date).getTime();
                }
            };
        },
        schoolChange(e) {
            this.formInline.schoolId = e
        },
        searchFetchData() {
            this.loading = true;
            let startDate =
        this.formInline.startDate == ''
          ? ''
          : moment(this.formInline.startDate).format('YYYY-MM-DD'); // 开始时间格式处理
            let endDate =
        this.formInline.endDate == ''
          ? ''
          : moment(this.formInline.endDate).format('YYYY-MM-DD'); // 结束时间格式处理
      // 初审1 复核 2
            pageCardSettlement(
        this.listQuery.page,
        this.config.pageSize,
        '2',
        this.formInline.fProvinceId,
        this.formInline.fCityId,
        this.formInline.fAreaId,
        this.formInline.schoolId,
        startDate,
        endDate,
        '',
        this.formInline.firstStatus
      )
        .then(data => {
            this.loading = false;
            this.dataList = data.data.content.list;
            this.listQuery.total = data.data.content.pagination.total;
        })
        .catch(Error => {
            this.loading = false;
        });
        },
        onSubmit() {
            this.listQuery.page = 1;
            this.searchFetchData();
        },
        handleSelectionChange(val) {
            this.multipleSelection = [];
            val.forEach(item => this.multipleSelection.push(item.pId));
        },
        fn(e) {
      // 判断是否为
            return Object.is(e.status, '未处理');
        },
        exportBtn() {
            if (this.multipleSelection.length > 0) {
                this.modifyAllow.dialogFormVisible = true;
                this.modifyAllow.length = this.multipleSelection.length;
                this.modifyAllow.pid = this.multipleSelection;
        // 初审 1表示初审通过 2表示复核通过
                this.modifyAllow.state = '2';
            } else {
                this.$message({ message: '请选择要通过的申请', type: 'warning' });
            }
        },
    // 分页
        handleSizeChange(val) {
            this.listQuery.page = 1;
            this.loading = true;
            this.ChangePageSize(val);
            this.searchFetchData();
        },
        handleCurrentChange(val) {
            this.loading = true;
            this.listQuery.page = val;
            this.searchFetchData();
        },
    // 复核
        btnTrial(e) {
            this.modifyTrial.dialogFormVisible = true;
            this.modifyTrial.pId = e.pId;
        },
    // 详情
        btnDetails(e) {
      // state 1 初审 2 复核 3 转账详情
            this.$router.push({
                path: `/unifyComposite/unifyGetDetails/${e.schoolId}/${e.pId}/2/${
          e.intervalStartTime
        }/${e.intervalEndTime}`
            });
        },
    // 复核更新
        sortTrial(e) {
            if (!e) {
                console.log('没有数据')
            } else {
        // 发现传递过来数据，刷新父组件的数据
                this.searchFetchData();
                this.$store.dispatch('UpdateCache', true);
            }
        },
        sortAllow(e) {
            if (!e) {
                console.log('111');
            } else {
                console.log('22');
        // 发现传递过来数据，刷新父组件的数据
                this.searchFetchData();
                this.$store.dispatch('UpdateCache', true);
            }
        }
    }
};
</script>
<style lang="scss" scoped>
.app-container {
  position: relative;
  padding: 20px 20px 10px;
}
.content {
  position: relative;
  padding: 0px;
  $bgcolor: #fff;
  .incomeTime {
    position: relative;
    padding-left: 10px;
    &::before {
      content: "*";
      position: absolute;
      left: 14px;
      top: 10px;
      color: #ff4949;
    }
  }
  .timeState {
    font-size: 12px;
    color: #ff4949;
    line-height: 1;
    padding-top: 4px;
    position: absolute;
    top: 100%;
    left: 0;
  }
  .withdrawals {
    width: 100%;
    background: #fff;
    padding: 30px 100px;
    margin-bottom: 20px;
    box-shadow: 0px 1px 2px #999;
    -webkit-box-shadow: 0px 1px 2px #999;
    .el-col {
      text-align: left;
      span {
        margin-left: 10px;
        font-size: 18px;
        display: inline-block;
      }
    }
  }
  .formInline {
    .formBtn {
      width: 100%;
      height: 70px;
      border-top: 1px solid #dddddd;
      position: relative;
      .btnPosition {
        position: absolute;
        right: 0px;
        top: 18px;
      }
    }
  }
}
.btn {
  color: #37a1fb;
}
.text-block {
  color: #000;
}
</style>                     